<template>
  <div class="app-container">
    
       

 

    <el-table :data="recordsList" border>
      <el-table-column type="expand">
      <template slot-scope="props">
        <el-form label-position="left" inline class="demo-table-expand" v-show="props.row.appRemark">
          <el-form-item label="审批意见:">
            <span v-html="props.row.appRemark"></span>
          </el-form-item>
        </el-form>
      </template>
    </el-table-column>
      <el-table-column label="流程节点名称" align="center" prop="appName" />
      <el-table-column label="处理人" align="center" prop="createName" />
      <el-table-column label="所属部门" align="center" prop="deptName" />
      <el-table-column label="处理时间" align="center" prop="createTime" />
      <el-table-column label="审批状态" align="center" prop="appStatu" />
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改审批计划对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="计划编码" prop="planCode">
          <el-input v-model="form.planCode" placeholder="请输入计划编码" />
        </el-form-item>
        <el-form-item label="流程节点名称" prop="appName">
          <el-input v-model="form.appName" placeholder="请输入流程节点名称" />
        </el-form-item>
        <el-form-item label="处理人" prop="createName">
          <el-input v-model="form.createName" placeholder="请输入处理人" />
        </el-form-item>
        <el-form-item label="所属部门" prop="deptName">
          <el-input v-model="form.deptName" placeholder="请输入所属部门" />
        </el-form-item>
        <el-form-item label="审批意见" prop="appRemark">
          <el-input v-model="form.appRemark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="审批状态" prop="appStatu">
          <el-input v-model="form.appStatu" placeholder="请输入审批状态" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listRecords, getRecords, delRecords, addRecords, updateRecords } from "@/api/purs/records";

export default {
  name: "Records",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 审批计划表格数据
      recordsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        planCode: null,
        appName: null,
        createName: null,
        deptName: null,
        appRemark: null,
        appType: null,
        appStatu: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询审批计划列表 */
    getList() {
      this.loading = true;
      listRecords(this.queryParams).then(response => {
        this.recordsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        flowId: null,
        planCode: null,
        appName: null,
        createName: null,
        deptName: null,
        createTime: null,
        appRemark: null,
        appType: null,
        appStatu: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.flowId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加审批计划";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const flowId = row.flowId || this.ids
      getRecords(flowId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改审批计划";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.flowId != null) {
            updateRecords(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRecords(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const flowIds = row.flowId || this.ids;
      this.$modal.confirm('是否确认删除审批计划编号为"' + flowIds + '"的数据项？').then(function() {
        return delRecords(flowIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('purs/records/export', {
        ...this.queryParams
      }, `records_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
